package com.school;

import java.util.Arrays;

public class StringBuilderdemo4 {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6};
        //调用方法
        System.out.println(Arrays.toString(arr));
        System.out.println(arrToString(arr));

        StringBuilder sb1=new StringBuilder();
        System.out.println(sb1.capacity());
        System.out.println(sb1.length());

        sb1.append("asdfghjklqwert");
        System.out.println(sb1.capacity());
        System.out.println(sb1.length());

        sb1.append("asdfghjklqwert5645");
        System.out.println(sb1.capacity());
        System.out.println(sb1.length());



    }

    //定义一个方法，把数组中的元素以逗号的形式拼接成一个字符串
    public static String arrToString(int[] arr){
        StringBuilder sb=new StringBuilder();
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            if(i==arr.length-1) {
                sb.append(arr[i]);
            }else{
                sb.append(arr[i]).append(",");
            }
        }
        sb.append("]");
     return sb.toString();
    }


}
